/*
	This program replicates the main results reported in Sections 4 and 5
*/


#include "setup.cpp"	       

#include "solveModel_EGM.cpp" 

#include "write_all.cpp" 



int main( int argc, char *argv[] ){

  	ifstream infile; 			
	gsl_vector * vecx = gsl_vector_alloc(Nvar);	
		
	
	
    init(); getpar_XWEPS_logwf(); 
	
    infile.open("estpar_iter.txt");         readpar(500, infile);    infile.close();
	infile.open("estpar_loglike_iter.txt"); readpar_loglike(500, infile);	infile.close(); 	
	
	
	// ... estiamte_loglike() was used to estimate measurement system parameters (MLE) 
//		estiamte_loglike();  
	
	// ... Predict cognitive factor score and non-cognitive factor score 
	test_loglike();  predict_unobs(); 	test_predict(); 
    
	
	// ... Update coefEmaxstate and initial distribution for structural model simulation 
	get_coefEmaxstate(); 
	init_sm0(0, NUM_smmPerson-1); 
	
    getvec(vecx); 
	getpar(vecx); 	
	
	
	// ... estiamte(vecx) was used to estimate structural parameters (SMM)
//		estiamte(vecx);  
	
	
	// ... Benchmark model simulation (Section 4)
	time_t start0,end0;	double timediff, temp_dis; 

	time (&start0);
	
	temp_dis = smm_obj(vecx,vecx); 
		
	time (&end0);	timediff = difftime (end0,start0);
    
    printf ("\n\n It took %f minutes to evaluate moment conditions, Initial distance = %f \n\n", timediff/60, temp_dis);
	
	int i_n = 0;
	outfiles_all("out_files", i_n); 
	write_input(1);
	

	
	// ... Counterfactual policy simulations: (1) causal effects of education on smoking (Section 5.1) 
	CF_model();   		write_input(0);   


	// ... Counterfactual policy simulations: (2) negative impact of youth smoking on education (Section 5.2) and corrective excise tax policy simulation (Section 5.3)
	CF_optTax_model();  write_input(0);   
   
   
  	write_input(0);   
	
  	
    printf ("\n\n Simulation Complete \n\n");
    
  	
	gsl_vector_free(vecx); 
	
 	
    return 0;
	
}


